<template>
	<view class="wrap">
		<view class="content" v-if="isShow">
			<!-- 头部 -->
			<view class="custom-header">
				<view class="title">{{ '新品尝鲜区' }}</view>
			</view>
			<!-- <oct-goods :lists="goodsArr" price-type="$" @onGoods="onGoods" /> -->
			<!-- 列表 -->
			<view class="toolList">
				<view class="toolItem" v-for="(subItem,index) in giftData" :key="index"
					@click="onGoods(subItem.effects)">
					<image :src="subItem.icon" mode="" class="item_icon"></image>
					<view class="tools-li__right">
						<p class="title">{{subItem.name}}</p>
						<p class="subtitle">等级{{subItem.price}}🌟</p>
					</view>
				</view>
				<view class="toolItem">
					<view class="tips">
						持续更新 点我更多
					</view>
				</view>
			</view>
		</view>
		<!-- svga动画 -->
		<view class="content gift-svga-ciew" v-if="!isShow">
			<l-svga ref="svga" style="z-index: 99999"></l-svga>
		</view>
	</view>
</template>

<script>
	import {
		giftData
	} from './gift.js'
	export default {
		data() {
			return {
				isShow: true,
				giftData: [],
				toolsData: [{
						icon: '../../static/logo.png',
						name: '三叶草',
						level: '🌟'
					},
					{
						icon: '../../static/logo.png',
						name: '三叶草',
						level: '🌟'
					}
				],
			}
		},
		onLoad() {
			
		},
		created() {
			this.giftData = giftData
		},
		methods: {
			onGoods(item) {
				uni.showLoading({
					title: '正在进入...'
				})
				// 隐藏tabbar
				uni.hideTabBar({
					animation: true, // 是否需要动画效果，默认为 false
					success: function() {}
				});
				this.isShow = false;
				console.log(this.$refs.svga, 'this.$refs.svga')
				this.$nextTick(() => {
					this.$refs.svga.render(async (parser, player) => {
						const videoItem = await parser.load(item);
						// let path = require('../../static/gift2527.svga')
						// const videoItem = await parser.load("@/static/gift2527.svga");
						await player.setVideoItem(videoItem);
						// 设置当前动画的循环次数，0代表无限循环 默认 0
						player.loops = 1
						// 开始播放动画，reverse = true 时则反向播放。
						player.startAnimation()
						uni.hideLoading();
						// 监听动画完成

						// 监听动画完成
						player.onFinished(() => {
							console.log("动画结束");
							this.isShow = true;
							uni.showTabBar()
						});
					})
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	// .wrap{
	// 	background: url('https://picnew13.photophoto.cn/20190228/lansegaoduankejiguangxiaolizihechengbeijing-33129736_1.jpg');
	// 	background-size: 100%;
	// 	background-repeat: no-repeat;
	// }
	.gift-svga-ciew {
		width: 100vw;
		height: 100vh;
		position: static;
		z-index: 1000;
		background-color: #000;
	}

	.custom-header {
		display: flex;
		justify-content: space-between;
		justify-content: center;
		align-items: center;
		height: 180rpx;
		background-color: #f7f7f7;

		.title {
			font-size: 18px;
			padding-top: 80rpx;
		}
	}

	.right-buttons {
		display: flex;
		align-items: center;
	}

	.right-buttons text {
		margin-left: 10px;
		font-size: 16px;
		color: #000;
		/* 添加点击效果的样式 */
		cursor: pointer;
	}

	.toolList {
		background: #FFFFFF;
		border-radius: 10px;
		margin: 0 10px 0;
		display: flex;
		padding: 0 0 20upx;
		justify-content: space-around;
		flex-wrap: wrap;
		height: 88vh;
		overflow-y: auto;

		.toolItem {
			height: 160upx;
			box-shadow: 1px 1px 2px #888888;
			width: calc(46% - 40upx);
			margin-top: 28upx;
			border-radius: 14upx;
			display: flex;
			align-items: center;
			padding: 0 20upx;

			.item_icon {
				width: 120upx;
				height: 120upx;
				margin-right: 20rpx;
			}

			.tools-li__right {
				.title {
					font-size: 32upx;
					margin-bottom: 20upx;
					color: #432847;
					// font-weight: 500;
				}

				.subtitle {
					color: #343434;
					font-size: 24upx;
				}
			}
		}
	}
</style>